package cn.gdcp.frame_animation_four_complementary_animation;

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private ImageView iv_wifi;
    private ImageView iv_yaya;
    private Button btnStart;
    private Button btnStop;
    private AnimationDrawable animationDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        iv_yaya = findViewById(R.id.iv_yaya);
        iv_wifi = findViewById(R.id.iv_wifi);
        btnStart = findViewById(R.id.btnStart);
        btnStop = findViewById(R.id.btnStop);

        animationDrawable = (AnimationDrawable) iv_wifi.getDrawable();

        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               animationDrawable.start();
                
                //图片透明度
//                starAlphaAnim();
                //图片平移
//                startTransAnim();
                //图片缩放
                starScaleAnim();
            }
        });

        btnStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                animationDrawable.stop();
            }
        });


    }

    private void starScaleAnim() {
        ScaleAnimation scaleAnimation = (ScaleAnimation) AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale_anim);
//        ScaleAnimation scaleAnimation = new ScaleAnimation(1,3,1,3);
//        scaleAnimation.setDuration(3000);
//        scaleAnimation.setFillAfter(true);
        iv_yaya.startAnimation(scaleAnimation);
    }

    private void startTransAnim() {
        TranslateAnimation translateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(
                MainActivity.this,R.anim.translate_anim);


//        TranslateAnimation translateAnimation = new TranslateAnimation(0,300,0,300);
//        translateAnimation.setDuration(3000);
//        translateAnimation.setFillAfter(true);
//        translateAnimation.setRepeatCount(-1);
//        translateAnimation.setRepeatMode(Animation.REVERSE);
        iv_yaya.startAnimation(translateAnimation);
    }


    private void starAlphaAnim() {
//        AlphaAnimation alphaAnimation =
//                AnimationUtils.loadAnimation(MainActivity.this,R.anim.alpah_anim);
       AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f,0.0f);
       alphaAnimation.setDuration(3000);
       alphaAnimation.setFillAfter(true);
       alphaAnimation.setRepeatCount(-1);
       alphaAnimation.setRepeatMode(Animation.REVERSE);
       iv_yaya.startAnimation(alphaAnimation);

    }
}




























